package org.jeecg.modules.zhima.portal.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.jeecg.common.api.vo.Result;
import org.jeecg.common.aspect.annotation.AutoLog;
import org.jeecg.common.system.base.controller.JeecgController;
import org.jeecg.common.system.query.QueryGenerator;
import org.jeecg.modules.zhima.admin.entity.ZmPlayerRanking;
import org.jeecg.modules.zhima.admin.service.IZmPlayerRankingService;
import org.jeecg.modules.zhima.portal.domain.PlayerRanking;
import org.jeecg.modules.zhima.portal.service.IPlayerRankingService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import javax.servlet.http.HttpServletRequest;

/**
* @Description: 选手排名
* @Author: jeecg-boot
* @Date:   2021-02-22
* @Version: V1.0
*/
@Api(tags="选手排名")
@RestController
@RequestMapping("/ranking")
@Slf4j
public class MZmRankingController extends JeecgController<ZmPlayerRanking, IZmPlayerRankingService> {

    @Autowired
    private IZmPlayerRankingService zmPlayerRankingService;
    @Autowired
    private IPlayerRankingService playerRankingService;

   /**
    * 分页列表查询
    *
    * @param zmPlayerRanking
    * @param pageNo
    * @param pageSize
    * @param req
    * @return
    */
   @AutoLog(value = "选手排名-分页列表查询")
   @ApiOperation(value="选手排名-分页列表查询", notes="选手排名-分页列表查询")
   @GetMapping(value = "/list")
   public Result<?> queryPageList(ZmPlayerRanking zmPlayerRanking,
                                  @RequestParam(name="pageNo", defaultValue="1") Integer pageNo,
                                  @RequestParam(name="pageSize", defaultValue="10") Integer pageSize,
                                  HttpServletRequest req) {
       QueryWrapper<ZmPlayerRanking> queryWrapper = QueryGenerator.initQueryWrapper(zmPlayerRanking, req.getParameterMap());
       Page<ZmPlayerRanking> page = new Page<ZmPlayerRanking>(pageNo, pageSize);
       IPage<PlayerRanking> pageList = playerRankingService.page(page, queryWrapper);
       return Result.OK(pageList);
   }

   /**
    *   添加
    *
    * @param zmPlayerRanking
    * @return
    */
   @AutoLog(value = "选手排名-添加")
   @ApiOperation(value="选手排名-添加", notes="选手排名-添加")
   @PostMapping(value = "/add")
   public Result<?> add(@RequestBody ZmPlayerRanking zmPlayerRanking) {
       zmPlayerRankingService.save(zmPlayerRanking);
       return Result.OK("添加成功！");
   }

   /**
    *  编辑
    *
    * @param zmPlayerRanking
    * @return
    */
   @AutoLog(value = "选手排名-编辑")
   @ApiOperation(value="选手排名-编辑", notes="选手排名-编辑")
   @PutMapping(value = "/edit")
   public Result<?> edit(@RequestBody ZmPlayerRanking zmPlayerRanking) {
       zmPlayerRankingService.updateById(zmPlayerRanking);
       return Result.OK("编辑成功!");
   }

   /**
    *   通过id删除
    *
    * @param id
    * @return
    */
   @AutoLog(value = "选手排名-通过id删除")
   @ApiOperation(value="选手排名-通过id删除", notes="选手排名-通过id删除")
   @DeleteMapping(value = "/delete")
   public Result<?> delete(@RequestParam(name="id",required=true) String id) {
       zmPlayerRankingService.removeById(id);
       return Result.OK("删除成功!");
   }

   /**
    * 通过id查询
    *
    * @param id
    * @return
    */
   @AutoLog(value = "选手排名-通过id查询")
   @ApiOperation(value="选手排名-通过id查询", notes="选手排名-通过id查询")
   @GetMapping(value = "/queryById")
   public Result<?> queryById(@RequestParam(name="id",required=true) String id) {
       ZmPlayerRanking zmPlayerRanking = zmPlayerRankingService.getById(id);
       if(zmPlayerRanking==null) {
           return Result.error("未找到对应数据");
       }
       return Result.OK(zmPlayerRanking);
   }

    /**
     * 计算排名
     * @return
     */
    @AutoLog(value = "赛事排名-计算")
    @ApiOperation(value = "赛事排名-计算", notes = "赛事排名-计算")
    @GetMapping(value = "/calculate")
    public Result<?> calculate() {
        return Result.OK(playerRankingService.calculate());
    }

}
